<template>
  <div class="layout">
    <Topnav toggleMenuButtonVisible class="nav" :toggle="false" />
    <div class="content">
      <transition name="wrapper">
        <div class="wrapper" v-if="menuVisible" @click="toggleMenu"></div>
      </transition>
      <transition name="aside">
        <aside v-if="menuVisible">
          <h2>文档</h2>
          <ol>
            <li>
              <router-link to="/doc/intro">介绍</router-link>
            </li>
            <li>
              <router-link to="/doc/install">安裝</router-link>
            </li>
            <li>
              <router-link to="/doc/get-started">开始使用</router-link>
            </li>
          </ol>
          <h2>组件列表</h2>
          <ol>
            <li v-for="(item, index) in componentList" :key="index">
              <router-link :to="item.path">{{ item.name }}</router-link>
            </li>
          </ol>
        </aside>
      </transition>
      <main>
        <router-view />
      </main>
    </div>
  </div>
</template>
<script lang="ts">
import Topnav from '../components/Topnav.vue'
import { inject, Ref } from 'vue'
export default {
  components: { Topnav },
  setup() {
    const menuVisible = inject<Ref<boolean>>('menuVisible') // get
    const width = document.documentElement.clientWidth
    const toggleMenu = () => {
      if (width < 500) {
        menuVisible.value = false
      }
    }

    const componentList = [
      { path: '/doc/switch', name: 'Switch 开关' },
      { path: '/doc/button', name: 'Button 按钮' },
      { path: '/doc/dialog', name: 'Dialog 对话框' },
      { path: '/doc/tabs', name: 'Tabs 标签页' },
      { path: '/doc/input', name: 'Input 输入框' },
      { path: '/doc/row', name: 'Layout 布局' },
      { path: '/doc/toast', name: 'Toast 吐司' },
      { path: '/doc/popover', name: 'Popover 弹出框' },
      // { path: '/doc/collapse', name: 'Collapse 手风琴' },
      { path: '/doc/cascader', name: 'Cascader 选择器' },
      { path: '/doc/uploader', name: 'Uploader 上传' },
      { path: '/doc/table', name: 'Table 表格' },
      { path: '/doc/pager', name: 'Pager 分页' },
    ]
    return { menuVisible, componentList, toggleMenu }
  },
}
</script>
<style lang="scss" scoped>
.layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  > .nav {
    flex-shrink: 0;
  }
  > .content {
    flex-grow: 1;
    padding-top: 60px;
    padding-left: 156px;
    @media (max-width: 500px) {
      padding-left: 0;
    }
  }
}
.content {
  display: flex;
  > aside {
    flex-shrink: 0;
  }
  > main {
    flex-grow: 1;
    padding: 16px;
    background: white;
  }
}
.wrapper {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: fade_out(black, 0.5);
  z-index: 10;
  @media (min-width: 500px) {
    display: none;
  }
}
.wrapper-enter-from,
.wrapper-leave-to {
  opacity: 0;
}
.wrapper-enter-active,
.wrapper-leave-active {
  transition: all 0.6s ease;
}
.aside-enter-from,
.aside-leave-to {
  left: -150px;
}
.aside-enter-active,
.aside-leave-active {
  transition: all 0.3s ease;
}
aside {
  background: white;
  width: 160px;
  position: fixed;
  z-index: 15;
  top: 0;
  left: 0;
  padding-top: 20px;
  height: 100%;
  @media (min-width: 500px) {
    box-shadow: 1px 0 10px rgba($color: #000000, $alpha: 0.1);
  }

  > h2 {
    margin: 6px 0;
    padding: 0 16px;
  }
  > ol {
    > li {
      a {
        display: block;
        padding: 8px 16px;
        text-decoration: none; // 删除a标签点击时的下划线
      }
      .router-link-active {
        // a标签激活时
        background: rgb(245, 245, 245);
      }
    }
  }
}
main {
  overflow: auto;
}
</style>
